<?php
namespace app\home\controller;
use app\common\controller\Home;	
class Gb extends Home{
   	public function show(){
		$param = zanpiancms_param_url();
		$Url=[];
		if($param['id']){
		    $Url['id']=$param['id'];
		}
		$Url['p']='[PAGE]';
		config('params',$Url);
		if($param['id']){
			$info = db('vod')->field('vod_id,vod_name,vod_cid,vod_actor')->find($param['id']);
			if($info){
				$this->assign($info);
				$this->assign('gb_content','影片ID'.$info['vod_id'].'点播出现错误！名称：'.$info['vod_name'].' 主演：'.$info['vod_actor']);
			}
		}
		if(is_login()){
		    $session =session('user_auth'); 
		    $this->assign($session);
		}
		$this->assign('param',$param); 
		if ($this->request->isAjax()){
			return $this->fetch(DS.'guestbook_ajax');
		}else{
            return $this->fetch(DS.'guestbook');		
		}
	}
    public function add(){
		$param = input();
        $gb=model('gb');
        $cookie='gb_time_'.ip2long(request()->ip());		
		if ($this->request->isPost()){
			if(!empty(cookie($cookie))){
				return $this->error("留言过快,请休息一会哦！");
            }
			if($GLOBALS['config']['user']['sys']['user_code'] == 1){
                if(!captcha_check($param['validate'])){
					return $this->error('验证码错误');
                }
            }
		    $data['gb_uid']=intval(is_login());	
		    $data['gb_cid']=input('post.gb_cid/d');
		    $data['gb_vid']=input('post.gb_vid/d',0);
		    $data['gb_nickname']=htmlspecialchars(strip_tags(input('post.gb_nickname/s')));
		    $data['gb_title']=htmlspecialchars(strip_tags(input('post.gb_title/s')));
		    $data['gb_content']=htmlspecialchars(strip_tags(input('post.gb_content/s')));
		    if($gb->validate('gb')->allowField(true)->save($data)!== false){
				cookie($cookie, 'gb_time_'.ip2long(request()->ip()),intval($GLOBALS['config']['user']['sys']['user_gb_time']));
			    if($GLOBALS['config']['user']['sys']['user_check']==1){
					return $this->success('留言成功,我们会尽快审核');
			    }
				return $this->success('留言成功');
		    }else{
				return $this->error($gb->getError());
		    }
		}
		
	}			
}
// +----------------------------------------------------------------------
// | ZanPianCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.zanpian.com All rights reserved.
// +----------------------------------------------------------------------
// | BBS:  <http://www.feifeicms.cc>
// +----------------------------------------------------------------------


